class CBASE extends egret.Sprite implements COllISION,EVENT {
	

	public objName:string;
	unjudge:CCOLLISION[]=[];
	judge:CCOLLISION[]=[];
	event:eventmassage[]=[];
	
	public constructor() {
		super()
		
	}
	public setjudgeshape_show_hide(sw:boolean,name?:number|string)
	{
		
       if(name==undefined)
	   {
          for(let a=0;a<this.judge.length;a++)
		  {
			 
			  this.judge[a].shapeCollisionSwitch=sw
		  }
	   }
	   else if(typeof(name)=="number")
	   {
		   if(name>=0&&name<this.judge.length)
          this.judge[name].shapeCollisionSwitch=sw
	   }
	   else
	   {
          for(let a=0;a<this.judge.length;a++)
		  {
			  if(this.judge[a].name==name)
			  this.judge[a].shapeCollisionSwitch=sw
		  }
	   }
	}
	public setunjudgeshape_show_hide(sw:boolean,name?:number|string)
	{
		 if(name==undefined)
	   {
          for(let a=0;a<this.unjudge.length;a++)
		  {
			  this.unjudge[a].shapeCollisionSwitch=sw
		  }
	   }
	   else if(typeof(name)=="number")
	   {
		   if(name>=0&&name<this.unjudge.length)
          this.unjudge[name].shapeCollisionSwitch=sw
	   }
	   else
	   {
          for(let a=0;a<this.unjudge.length;a++)
		  {
			  if(this.unjudge[a].name==name)
			  this.unjudge[a].shapeCollisionSwitch=sw
		  }
	   }
	}
	public addevent(string:string,func:string,ptr:any)
	{
		if(string!=events.beginjudge&&string!=events.combojudge&&string!=events.endjudge)
		  //查询重复
	      for(let a=0;a<this.event.length;a++)
		  {
			  if(this.event[a].event_event==string&&this.event[a].event_func==func&&this.event[a].event_ptr==ptr)
			  return;
		  }
		  this.event.push(new eventmassage(string,func,ptr))
		
    }
	public addjudgeevent(string:string,func:string,ptr:any,child_name?:string)
	{
		if(string==events.beginjudge||string==events.combojudge||string==events.endjudge)
		{
            if(child_name==undefined)
			{
				var names=this.getjudgename()
				for(let a=0;a<names.length;a++)
				{
					let bool=true
					//查找是否重复
					for(let b=0;b<this.event.length;b++)
					{
						if(this.event[b].child_name==names[a]&&this.event[b].event_event==string&&this.event[b].event_func==func&&this.event[b].event_ptr==ptr)
                        {
							bool=false;
							break;

						}
					}
					//未重复依次添加
					if(bool)
					{
					this.event.push(new eventmassage(string,func,ptr,names[a]));
					}
				}
				COLLISION_MANAGE.getCOLLISIONCONTRL.ADDjudge(this)
			}
			else 
			{
				//查找是否重复
				for(let b=0;b<this.event.length;b++)
					{
						if(this.event[b].child_name==child_name&&this.event[b].event_event==string&&this.event[b].event_func==func&&this.event[b].event_ptr==ptr)
                        {
							return;
						}
					}
					//未重复则添加
				this.event.push(new eventmassage(string,func,ptr,child_name))
				COLLISION_MANAGE.getCOLLISIONCONTRL.ADDjudge(this)
			}
		}
	}
	public sendevent(string:string,obj?:Object,target_name?:string,child_name?:string)
	{
		    for(let a=0;a<this.event.length;a++)
	       {
		   if(this.event[a].event_event==string&&obj==undefined&&target_name==undefined)
		   {
				this.event[a].event_ptr[this.event[a].event_func]();
		   }
		   else  if(this.event[a].event_event==string&&obj!=undefined&&target_name==undefined)
		   {
				this.event[a].event_ptr[this.event[a].event_func](obj);
		   }
		   else if(this.event[a].event_event==string&&this.event[a].child_name==child_name)
		   {
			   
			  this.event[a].event_ptr[this.event[a].event_func](obj,target_name,child_name);
		   }
	       }
		
	}
	public removejudgeevent(string:string,func:string,ptr:any,child_name?:string)
	{
      if(string==events.beginjudge||string==events.combojudge||string==events.endjudge)
		{
            if(child_name==undefined)
			{
				var names=this.getjudgename()
				for(var a=0;a<this.event.length;a++)
				{
				for(let b=0;b<names.length;b++)
				 {
					
				    if(this.event[a].event_func==func&&this.event[a].event_ptr==ptr&&this.event[a].event_event==string&&this.event[a].child_name==name[b])
					 {
						 this.event.splice(a,1)
						 a--;
					 }
				 }
				}
				COLLISION_MANAGE.getCOLLISIONCONTRL.removejudge(this)
			}
			else 
			{
				let eventnumber=0;
				for(var a=0;a<this.event.length;a++)
				{
					if(this.event[a].event_func==events.beginjudge||this.event[a].event_func==events.combojudge||this.event[a].event_func==events.endjudge)
					{
						eventnumber++;
					}
					if(this.event[a].event_func==func&&this.event[a].event_ptr==ptr&&this.event[a].event_event==string&&this.event[a].child_name==child_name)
	                 {
						 
						 this.event.splice(a,1)
						 eventnumber--;
						 a--;
					 }
				}
				//全部移除完毕
				if(!eventnumber)COLLISION_MANAGE.getCOLLISIONCONTRL.removejudge(this)
				
				
			}
		}
	}
	public removeevent(string:string,func:string,ptr:any)
	{
       if(string!=events.beginjudge&&string!=events.combojudge&&string!=events.endjudge)
	 
           for(var a=0;a<this.event.length;a++)
	      {
			if(this.event[a].event_func==func&&this.event[a].event_event==string&&this.event[a].event_ptr==ptr)
		   {
                this. event.splice(a,1)
				a--;
			}
					
		   }
	   
	}
	 public ALLunjudge_tojudge()
	{
		for(let a=0;a<this.unjudge.length;a++)
		{
			this.unjudge[a].judgeswitch=true;
			this.judge.push(this.unjudge[a])
		}
		this.unjudge=[];
	}
	public addbox_judge(a:judgetype)
	{
		
      switch(a)
	  {
		 
		  case judgetype.circle:
		  {
            let box=new CCOLLISION_CIRCLE(this,this.height/2,this.width/2,this.height>this.width?this.width:this.height)
			box.judgeswitch=true;
			this.judge.push(box)
		  }break;
		  case judgetype.poly:
		  {
            let box=new CCOLLISION_CIRCLE(this,this.height/2,this.width/2,this.height>this.width?this.width:this.height)
			box.judgeswitch=true;
			this.judge.push(box)
		  }break;
		  case judgetype.rectangle:
		  {
            let box=new CCOLLISION_RECT(this,this.x,this.y,this.height,this.width)
			box.judgeswitch=true;
			this.judge.push(box)
		  }break;
	  }
	}
	public addbox_rectjudge(nowjudge?:boolean,x?:number,y?:number,w?:number,h?:number,color?:number)
	{
		var box:CCOLLISION
        if(x==undefined||y==undefined||w==undefined||h==undefined)
		{
		   box=new CCOLLISION_RECT(this,this.x,this.y,this.width,this.height,color)
		  
		}
		else
		{
		  box=new CCOLLISION_RECT(this,x,y,w,h,color)
		}
		box.judgeswitch=nowjudge;
		if(nowjudge==false)
		{
			
           this.unjudge.push(box)
		}
		else
		{
            
	      this.judge.push(box);
		}
		
	}
	public addbox_circlejudge(nowjudge?:boolean,x?:number,y?:number,r?:number,color?:number)
	{
		let box:CCOLLISION
        if(x==undefined||y==undefined||r==undefined)
		{
		  box=new CCOLLISION_CIRCLE(this,this.height/2,this.width/2,this.height>this.width?this.width:this.height)
	     
		}
		else
		{
		  box=new CCOLLISION_CIRCLE(this,x,y,r,color)
		}
		box.judgeswitch=nowjudge;
		if(nowjudge==false)
		{
           this.unjudge.push(box)
		}
		else
		{
       
	      this.judge.push(box);
		}
		
	}
	public addbox_polyjudge(nowjudge:boolean,p1:egret.Point,p2:egret.Point,p3:egret.Point,p4?:egret.Point,p5?:egret.Point,color?:number)
	{
		let box:CCOLLISION
      
		box=new CCOLLINSION_POLY(this,p1,p2,p3,p4,p5,color)
		box.judgeswitch=nowjudge;
		if(nowjudge==false)
		{
           this.unjudge.push(box)
		}
		else
		{
	      this.judge.push(box);
		}
		
	}
	public getjudgename():string[]
	{
		var name:string[]=[]
		for(let a=0;a<this.judge.length;a++)
		{
          name.push(this.judge[a].name)
		}
		return name
	}
	public getjudgeByname(name:string):CCOLLISION
	{
		for(let a=0;a<this.unjudge.length;a++)
		{
          if(this.unjudge[a].name==name)
		  return this.unjudge[a]
		}
		for(let a=0;a<this.judge.length;a++)
		{
          if(this.judge[a].name==name)
		  return this.judge[a]
		}
	}
	public removejudge_tounjudge(index:number|string)
	{
		if(typeof(index)=="number")
		{
			if(index<this.judge.length&&index>=0)
			{
				 this.judge[index].judgeswitch=false
                 this.unjudge.push(this.judge[index])
				 this.judge.splice(index,1)
			}
			
		}
		else
		{
        for(let a=0;a<this.judge.length;a++)
		{
			if(this.judge[a].name==index)
			{
				 this.judge[a].judgeswitch=false
				this.unjudge.push(this.judge[a])
				this.judge.splice(a,1)
			}
		}
		}
	
	}
	public addunjudge_tojudge(index:number|string)
	{
		if(typeof(index)=="number")
		{
			if(index<this.unjudge.length&&index>=0)
			{
				this.unjudge[index].judgeswitch=true
                 this.judge.push(this.unjudge[index])
				 this.unjudge.splice(index,1)
			}
			
		}
		else
		{
        for(let a=0;a<this.unjudge.length;a++)
		{
			if(this.unjudge[a].name==index)
			{
				 this.unjudge[a].judgeswitch=true
				this.judge.push(this.unjudge[a])
				this.unjudge.splice(a,1)
			}
		}
		}
	
	}
	public removejudgebox(index:number|string)
	{
        if(typeof(index)=="number")
		{
			if(index<this.judge.length&&index>=0)
			{
				this.removeChild(this.judge[index].shape)
				 this.judge.splice(index,1)
			}
			
		}
		else
		{
          for(let a=0;a<this.judge.length;a++)
	      {
			if(this.judge[a].name==index)
			{
				this.removeChild(this.judge[a].shape)
				this.judge.splice(a,1)
			}
		  }
		}
	}
	public removeunjudgebox(index:number|string)
	{
		if(typeof(index)=="number")
		{
			if(index<this.unjudge.length&&index>=0)
			{
				this.removeChild(this.unjudge[index].shape)
				 this.unjudge.splice(index,1)
			}
			
		}
		else
		{
          for(let a=0;a<this.unjudge.length;a++)
	      {
			if(this.unjudge[a].name==index)
			{
				this.removeChild(this.unjudge[a].shape)
				this.unjudge.splice(a,1)
			}
		  }
		}
	
	}




	
}